spectrogram: fix FFT result scaling factor
authorMaxime Even <maximeeven@proton.me>
Tue, 9 Jul 2024 11:20:25 +0000 (13:20 +0200)
committerSebastian Ramacher <sramacher@debian.org>
Tue, 14 Jan 2025 22:09:47 +0000 (23:09 +0100)
commitdae21e0709731ffc1723d11ff2963acbe2b2e8ad
tree3abada91bb15b733e54a06784be76768d50bfd36
parent3056fa32cc30ad2189e6046be9b586564c14f592
spectrogram: fix FFT result scaling factor

This function is just a scaling operation that passes a value between 0 and
FFT_SCALING_VALUE to a value between 0 and 2^16-1.

It is therefore a power that must be applied here and not a xor.

Moreover, the initial formula was quite wrong since it was assuming that the max_input
value, which is a signed int 16, was 2^15 = 32768 where it is in fact 2^15-1=32767.

Moreover, the initial formula wasn't taking into account that, since the
output of the fft_perform is the sum of two variables which have for max value
(FFT_BUFFER_SIZE / 2 * INT16_MAX)^2, then we need to multiply the final max
value by 2.

Corrects the following compiler warnings:
visualization/glspectrum.c:528:43: warning: result of ‘2^16’ is 18; did you mean ‘1 << 16’ (65536)? [-Wxor-used-as-pow]
visualization/visual/effects.c:216:40: warning: result of ‘2^16’ is 18; did you mean ‘1 << 16’ (65536)? [-Wxor-used-as-pow]

Fixes #28506

Co-authored-by: Disha Baghel <bagheldisha708@gmail.com>
(cherry picked from commit 77a08a60f72bda081d144119e4d0a57a9c3c72f6)

Gbp-Pq: Name 0015-spectrogram-fix-FFT-result-scaling-factor.patch
modules/visualization/glspectrum.c
modules/visualization/visual/effects.c
modules/visualization/visual/fft.h